/**
 * @author 
 */

function jumpTo(lon, lat, zoom) {
    var x = Lon2Merc(lon);
    var y = Lat2Merc(lat);
    map.setCenter(new OpenLayers.LonLat(x, y), zoom);
    return false;
}
 
function Lon2Merc(lon) {
    return 20037508.34 * lon / 180;
}
 
function Lat2Merc(lat) {
    var PI = 3.14159265358979323846;
    lat = Math.log(Math.tan( (90 + lat) * PI / 360)) / (PI / 180);
    return 20037508.34 * lat / 180;
}
 
function addMarker( layer, lon, lat, popupContentHTML, showpopup) {       
	
	
	
	var ll = new OpenLayers.LonLat(Lon2Merc(lon), Lat2Merc(lat));     
	var data = {};         
	data.icon = new OpenLayers.Icon('../img/icon.jpg',                                         
					new OpenLayers.Size(21, 25),                                          
					new OpenLayers.Pixel(-18, -18)
	);      
	

	var feature = new OpenLayers.Feature(layer, ll);  
	
	
	feature.closeBox = true;     
	feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
		minSize: new OpenLayers.Size(300, 200) 
		});     
	feature.data.popupContentHTML = popupContentHTML;     
	feature.data.overflow = "hidden";       
	var marker = new OpenLayers.Marker(ll, data.icon);     
	marker.feature = feature;        
	/*var markerClick = function(evt) {         
		if (this.popup == null) {             
			
			this.popup = this.createPopup(this.closeBox);            
			 map.addPopup(this.popup);             
			 this.popup.show();
			 feature.popup = this.popup;
		} 
		else {             
			
			this.popup.toggle();         
		}
	*/
	var markerClick = function(evt) {
        // Wenn das Popup nicht sichtbar ist, dann kann es nicht fest sichtbar sein
		if (this.popup == null) {             
			
			 this.popup = this.createPopup(this.closeBox);            
			 map.addPopup(this.popup);             
			 this.popup.show();
			 feature.popup = this.popup;
		} 
		else {             
			
			this.popup.toggle();         
		}
		OpenLayers.Event.stop(evt);     
	};     
	marker.events.register("mousedown", feature, markerClick);
	layer.addMarker(marker);    
	feature.popup = null;

}
 
function getCycleTileURL(bounds) {
   var res = this.map.getResolution();
   var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
   var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
   var z = this.map.getZoom();
   var limit = Math.pow(2, z);
 
   if (y < 0 || y >= limit)
   {
     return null;
   }
   else
   {
     x = ((x % limit) + limit) % limit;
 
     return this.url + z + "/" + x + "/" + y + "." + this.type;
   }
}